package com.yehun.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;

/**
 * mongoTemplate获取
 * Created by Genius on 2017/3/31 0031.
 */
@Component
@Repository("mongoDataSource")
public class MongoDataSource {

    @Autowired
    private MongoTemplate mongoTemplate;
    private static MongoDataSource mongoDataSource;
    public static MongoTemplate getMongoTemplate() {
        return mongoDataSource.mongoTemplate;
    }

    @PostConstruct
    public void init() {
        mongoDataSource = this;
        mongoDataSource.mongoTemplate = this.mongoTemplate;
    }
}